﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Instrument
{
    public class AC_Source:Visa
    {
        public AC_Source(string szInsID)
            : base(szInsID)
        {
        }

        public string Set_VF(float Volt, float Fin)
        {
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "SOUR:VOLT " + Volt.ToString() + ";FREQ " + Fin.ToString() + "\n";
            this.Write(szCmd);
            szRet = this.Query("SYST:ERR?\n");
            if (szRet == "0,No Error\r\n")
            {
                szCmd = "OUTP ON\n";
                this.Write(szCmd);
                szCmd = "SYST:ERR?\n";
                szRet = this.Query(szCmd);
            }

            return szRet;
        }

        public double Meas_Volt()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:VOLT:AC?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public double Meas_Curr()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:CURR:AC?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public double Meas_Power()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:POW:AC?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public void ONorOFF(bool NF)
        {
            this.Write("*CLS\n");
            this.Write(NF ? "OUTP ON\n" : "OUTP OFF\n");
        }

        public string Query_Type()
        {
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "*IDN?\n";
            szRet = this.Query(szCmd);
            return szRet;
        }
    }
}
